package uit.ce.hungtrung;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import uit.ce.hungtrung.game.lib.game2d.Sprite;

public class Egg extends Entity {
	private final int SCR_WIDTH, SCR_HEIGHT;
	private byte speed = 0;

	private final byte STATE_STAND = 0;
	private final byte STATE_FLY_UP = STATE_STAND + 1;
	private final byte STATE_FLY_DOWN = STATE_FLY_UP + 1;

	private byte sateEgg = STATE_STAND;

	private int pX, pY;

	private byte stateEgg = 0;
	private boolean isCollisWith = true;
	private boolean isFly = false;

	private long time;
	private byte t = 0;

	public Egg(Context context, int scr_Width, int scr_Height) {
		super(context, R.drawable.egg);
		this.SCR_WIDTH = scr_Width;
		this.SCR_HEIGHT = scr_Height;
		time = System.currentTimeMillis();

	}

	public void Render(Canvas canvas) {
		Draw(canvas);
	}

	protected void Draw(Canvas canvas) {
		setPositionXY(currentX, currentY);
		sprite.DrawIamge(canvas);
		// Paint myPaint = new Paint();
		// myPaint.setColor(Color.rgb(0, 0, 0));
		// canvas.drawRect(200, 600, 100, 100,
		// myPaint);
	}

	public void Update() {
		if (isFly) {
			isCollisWith = false;
			speed = 35;
			currentY += -speed + 2.0f * t;
			t++;
		} else if (!isFly) {
			t = 0;
			speed = 0;
		}
	}

	public boolean isCollition(float x, float y) {
		if (sprite.isCollition(x, y))
			return true;
		return false;
	}

	// lấy vị trí hiện tại của quả trứng getPositionY()

	public boolean isCollisWith(Entity e) {
		if ((-speed + 2.0f * t) >= 0) {
			if (getPositionY() <= e.getPositionY()
					&& getPositionY() >= e.getPositionY()
							- getSprite().getHeight() / 2) {
				if (getPositionX() > e.getPositionX()
						&& (getPositionX() < e.getPositionX()
								+ (e.getSprite().getWidth() / 4) * 3))
					return true;
			}
		}
		return false;
	}

	public void setPositionInBasket(Entity e) {
		setPositionXY(e.getPositionX() + e.getSprite().getWidth() / 2
				- this.getSprite().getWidth() / 2, e.getPositionY()
				- e.getSprite().getHeight() / 2);
	}

	public void setPositionInBasketX(Entity e) {
		setPositionX(e.getPositionX() + e.getSprite().getWidth() / 2
				- this.getSprite().getWidth() / 2);
	}

	public boolean isFly() {
		return isFly;
	}

	public void setFly(boolean isFly) {
		this.isFly = isFly;
	}

	public boolean isCollis() {
		return isCollisWith;
	}

	public void setCollis(boolean isTouch) {
		this.isCollisWith = isTouch;
	}

	public void setpY(int y) {
		this.pY = y;
	}

}
